export const panelColor = [
  ['#ffffff', '#f2f2f2', '#d8d8d8', '#bfbfbf', '#a5a5a5', '#939393'],
  ['#000000', '#7f7f7f', '#595959', '#3f3f3f', '#262626', '#0d0d0d'],
  ['#485368', '#f3f5f7', '#c5cad3', '#808b9e', '#353b45', '#24272e'],
  ['#2972f4', '#e5efff', '#c7dcff', '#99beff', '#1450b8', '#0c306e'],
  ['#00a3f5', '#e5f6ff', '#c7ecff', '#99ddff', '#1274a5', '#0a415c'],
  ['#319b62', '#eafaf1', '#c3ead5', '#98d7b6', '#277c4f', '#184e32'],
  ['#de3c36', '#ffe9e8', '#ffc9c7', '#ff9c99', '#9e1e1a', '#58110e'],
  ['#f88825', '#fff3eb', '#ffdcc4', '#ffba84', '#b86014', '#5c300a'],
  ['#f5c400', '#fff9e3', '#ffeead', '#ffe270', '#a38200', '#665200'],
  ['#9a38d7', '#fdebff', '#f2c7ff', '#d58eff', '#5e2281', '#3b1551']
];
// 标准色值
export const standardColor = ['#ae2e19', '#e74025', '#f4c243', '#fefb54', '#a1ce63', '#53ad5b', '#53aeea', '#326fba', '#0a205c', '#67359a'];
// 常用色值
export const commColor = ['#e74025', '#fefb54', '#f2f2f2', '#485368', '#ffffff', '#ffffff', '#ffffff', '#ffffff', '#ffffff', '#ffffff'];
// rgb转16进制
export function rgbToHex(color) {
  try {
    const start = color.indexOf('(');
    const end = color.indexOf(')');
    const list = color.substring(start + 1, end).split(',');
    const r = Number(list[0]),
      g = Number(list[1]),
      b = Number(list[2]);
    //十六进制颜色值的正则表达式
    return '#' + fAddZero(r.toString(16)) + fAddZero(g.toString(16)) + fAddZero(b.toString(16));
  } catch (error) {
    console.log(error);
    return color;
  }
}
function fAddZero(v) {
  const newv = '00' + v;
  return newv.substring(newv.length - 2, newv.length);
}
// rgba 透明度更改
export function rgbOpacity(rgbaText, opacity = 1) {
  opacity = Number(opacity.toFixed(2));
  const start = rgbaText.indexOf('(');
  const end = rgbaText.indexOf(')');
  const list = rgbaText.substring(start + 1, end).split(',');
  list[list.length - 1] = `${opacity}`;
  return `rgba(${list.join(',')})`;
}

/**
 * @Author: 刘强
 * @description: 渐变色
 * @param {string} startColor
 * @param {string} endColor
 * @param {number} num
 * @return {*}
 */
function fColorGradualChange(startColor, endColor, num) {
  const rgb = /^rgb|RGB\((([0-9]|[1-9]\d|1\d\d|2([0-4]\d|5[0-5])),){2}([0-9]|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\)$/; //rgb
  const hex = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i; //16进制
  //颜色预处理
  let startRGB, endRGB;
  if (hex.test(startColor)) {
    startRGB = fAnalysisRGB(startColor);
  } else if (rgb.test(startColor)) {
    startRGB = startColor.substring(3, 15).split(',');
  }
  if (hex.test(endColor)) {
    endRGB = fAnalysisRGB(endColor);
  } else if (rgb.test(startColor)) {
    endRGB = endColor.substring(3, 15).split(',');
  }
  const startR = startRGB[0],
    startG = startRGB[1],
    startB = startRGB[2];
  const endR = endRGB[0],
    endG = endRGB[1],
    endB = endRGB[2];
  const sR = (endR - startR) / num;
  const sG = (endG - startG) / num;
  const sB = (endB - startB) / num;
  const colors = [];
  for (let i = 0; i < num; i++) {
    const param = `rgba(${parseInt(sR * i + startR, 10)},${parseInt(sG * i + startG, 10)},${parseInt(sB * i + startB, 10)},1)`;
    colors.push(param);
  }
  return colors;
}
/**
 * @Author: 刘强
 * @description: 16进制转化rgb
 * @param {string} temp
 * @return {*}
 */
function fAnalysisRGB(temp) {
  temp = temp.toLowerCase().substring(1, temp.length);
  const colors = [];
  colors.push(parseInt(temp.substring(0, 2), 16));
  colors.push(parseInt(temp.substring(2, 4), 16));
  colors.push(parseInt(temp.substring(4, 6), 16));
  return colors;
}
export function getColor(value) {
  value = value * 10;
  const step = 10;
  const colorZone = parseInt(`${value / step}`, 10);
  const index = parseInt(`${value % step}`, 10);
  let s = [];
  switch (colorZone) {
    case 0:
      s = fColorGradualChange('#FF0000', '#FF9A00', step);
      return s[index];
    case 1:
      s = fColorGradualChange('#FF9A00', '#CCFF00', step);
      return s[index];
    case 2:
      s = fColorGradualChange('#CCFF00', '#33FF00', step);
      return s[index];
    case 3:
      s = fColorGradualChange('#33FF00', '#00FF67', step);
      return s[index];
    case 4:
      s = fColorGradualChange('#00FF67', '#00FFFF', step);
      return s[index];
    case 5:
      s = fColorGradualChange('#00FFFF', '#0066FF', step);
      return s[index];
    case 6:
      s = fColorGradualChange('#0066FF', '#3300FF', step);
      return s[index];
    case 7:
      s = fColorGradualChange('#3300FF', '#CC00FF', step);
      return s[index];
    case 8:
      s = fColorGradualChange('#CC00FF', '#FF0099', step);
      return s[index];
    case 9:
      s = fColorGradualChange('#FF0099', '#FF0000', step);
      return s[index];
    case 10:
      return 'rgba(255,0,0,1)';
    default:
      return 'rgba(255,0,0,1)';
  }
}
//
// #ffffff - #ff0000
// #ffffff - #000000
// #ff0000 - #000000
// 色域规则模板
export function colorCursor(color, x, y) {
  color = rgbToHex(color);
  x = Number(x.toFixed(0));
  y = Number(y.toFixed(0));
  const step = 100;
  let result1 = '';
  let result2 = '';
  // x白色无法取极致
  if (x === 100) {
    result1 = 'rgba(255,255,255,1)';
  } else {
    result1 = fColorGradualChange(color, '#ffffff', step)[x];
  }
  // y黑色无法取极致 y=100时为黑色直接返回
  if (y === 100) {
    return 'rgba(0,0,0,1)';
  } else {
    result2 = fColorGradualChange(color, '#000000', step)[y];
  }
  // 综合结果
  return fColorGradualChange(rgbToHex(result1), rgbToHex(result2), step)[y];
}
